package reflect;


import java.util.Scanner;

/**
 * 反射机制实例化对象
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Person p=new Person();
        System.out.println(p);
////反射机制实例化对象
////        1、获取对应类对象
//        Class cls=Class.forName("reflect.Person");
////        2、类对象提供了实例化的方法newInstance（）
//        Object obj=cls.newInstance();
////        Object obj=new Person();
//        System.out.println(obj);
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入类名");//reflect.Student/Person;  java.lang.String  java.io.FileInputStream
        String className=scanner.nextLine();
        Class cls=Class.forName(className);
        Object obj=cls.newInstance();
        System.out.println(obj);
    }
}
